<template>
  <div class="side">
    <!-- el-sub-menu是多级的 -->
    <el-menu
      active-text-color="#409eff"
      background-color="#304156"
      class="el-menu-vertical-demo"
      :default-active="defUrl"
      text-color="#fff"
      :collapse="store.collapse"
      router
      unique-opened
    >
      <el-menu-item index="/index">
        <i class="iconfont homepage"></i>
        <span>首页</span>
      </el-menu-item>
      <!-- 权限 -->
      <el-sub-menu
        v-for="item in menus"
        :key="item.id"
        :index="'/' + item.name"
      >
        <template #title>
          <i class="iconfont" :class="item.icon"></i>
          <span>{{ item.title }}</span>
        </template>
        <template v-for="citem in item.children" :key="citem.id">
          <el-menu-item
            :index="`/${item.name}/${citem.name}`"
            v-if="citem.hidden === 0"
          >
            <i class="iconfont" :class="citem.icon"></i>
            <span>{{ citem.title }}</span>
          </el-menu-item>
        </template>
      </el-sub-menu>
    </el-menu>
    <!-- <button @click="isCollapsefn">按钮</button> -->
  </div>
</template>

<script setup lang="ts">
import { useHome } from "@/store/home";
import { useUserKey } from "@/store/user";
import { ref, watch } from "vue";
import { useRoute } from "vue-router";
const store = useHome();
const userStore = useUserKey();
// 菜单数组筛选
const menus = userStore.routes;
// 默认路由 默然展开side在当前的
const defUrl = ref("/index");
const route = useRoute();
// console.log(route.path);

watch(
  () => route.path,
  () => {
    defUrl.value = route.path;
  },
  {
    immediate: true,
  }
);
</script>

<style lang="less" scoped>
.side {
  .el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 250px;
    min-height: 400px;
  }
  :deep(.el-menu) {
    border: none;
    // height: calc(100vh - 70px);
    // background-color: #304156;
    // width: 250px;
    box-sizing: content-box;
    .el-icon {
      margin-right: 20px;
    }
  }
}
</style>
